package com.tnxst.phexamination.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.RecyclerView;

import com.tnxst.phexamination.R;
import com.tnxst.phexamination.dto.ServiceDetailsDTO;
import com.tnxst.phexamination.dto.ServicePackageDTO;
import com.tnxst.phexamination.fragment.PackageServiceFragment;

import java.util.List;

public class ServiceDetailsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;

    private List<ServiceDetailsDTO> serviceDetailsDTOS;




    public ServiceDetailsAdapter(List<ServiceDetailsDTO> serviceDetailsDTOS) {
        this.serviceDetailsDTOS = serviceDetailsDTOS;
    }

    public void setSignPackages(List<ServiceDetailsDTO> serviceDetailsDTOS) {
        this.serviceDetailsDTOS = serviceDetailsDTOS;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view =  LayoutInflater.from(context).inflate(R.layout.service_details_item,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        ViewHolder holders = (ViewHolder) holder;
        ServiceDetailsDTO serviceDetailsDTO = serviceDetailsDTOS.get(position);

        if (serviceDetailsDTO != null){
            if (serviceDetailsDTO.getNAME() != null)
                holders.name.setText(serviceDetailsDTO.getNAME());
            if (serviceDetailsDTO.getFRE_NUM() != null)
            holders.num.setText(serviceDetailsDTO.getFRE_NUM());
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        TextView name;

        TextView num;

        public ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.textView1);
            num = itemView.findViewById(R.id.textView2);
        }
    }

    @Override
    public int getItemCount() {
        return serviceDetailsDTOS.size();
    }
}
